home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / maxs / dfbv13.lha / dfb / Developers / dfb_read.s < prev    next >
Text File  |  1996-06-01  |  3KB  |  145 lines

  1. ;
  2. ; DFB_read - Example of how to open the file base, read in the files and
  3. ;            also how to use the built in display routine
  4. ;            This programme lists all files to the current CLI window in ANSI
  5. ;            text.
  6.  
  7.  
  8.             include    exec/types.i
  9.             include    exec/exec_lib.i
  10.             include    exec/memory.i
  11.             include    exec/strings.i
  12.             include    libraries/dos_lib.i        
  13.             include    libraries/dos.i
  14.             include    dfb.i
  15.             include    dfb_lib.i
  16.             
  17.             lea        dfbname,a1                ;load all needed libraries
  18.             moveq    #0,d0
  19.             CALLEXEC    OpenLibrary
  20.             tst.l    d0
  21.             beq        nolibrary
  22.             move.l    d0,_dfbbase
  23.  
  24.             lea        dosname,a1
  25.             moveq    #0,d0
  26.             CALLEXEC    OpenLibrary
  27.             tst.l    d0
  28.             beq        nodoslibrary
  29.             move.l    d0,_dosbase
  30.         
  31.             CALLDOS Output                    ;get output handle since we are            
  32.             move.l    d0,CliHandle            ;writing to CLI window
  33.  
  34.             move.l    #ATSTART,d0                ;we want to read forward so go start
  35.             CALLDFB    OpenFileBase            ;open the file base
  36.             tst.l    d0
  37.             beq        nofilebase
  38.             move.l    d0,a5
  39.  
  40. ReadNextFile
  41.             clr.l    d4
  42.             move.w    of_nextlength(a5),d4    ;get the length of the next
  43.             tst.w    d4                        ;file node. So we can allocate
  44.             beq        nomorefiles             ;enough memory to load it
  45.             move.l    d4,d0                    ;if d4=0 no more files.
  46.             move.l    #MEMF_PUBLIC,d1
  47.             CALLEXEC    AllocMem
  48.             tst.l    d0
  49.             beq        nomorefiles            
  50.  
  51.             move.l    d0,a4                        
  52.  
  53.             move.l    d0,a0                    ;memory for file node
  54.             move.l    a5,d0                    ;file base handle
  55.             clr.l    d1                        ;standard mode
  56. readfile
  57.             CALLDFB    ReadNextFile            ;Read the next file node in
  58.             tst.l    d0
  59.             bne        errorinread                ;any problems?
  60.  
  61.             move.l    a4,a0                    ;file node to display
  62.             btst    #fbb_astalavista,fb_status(a4)    ;use this file node ?
  63.             bne        DonePrinting
  64.  
  65.             lea        freespace,a1            ;free space (1Kb)
  66.             lea        clearbyte,a2            ;no marked files, so point to empty byte            
  67.             move.l    a5,a3                    ;file base handle
  68.             suba.l    a4,a4                    ;use standard layout data
  69.             clr.l    d0                        ;length of marked list
  70.             clr.l    d1                      ;no name offset 
  71.             clr.l    d2                      ;display all data                        
  72.             move.l    #5000,d3                 ;list files as so we were a sysop (access 5000)
  73.             CALLDFB    DisplayNode                ;this puts everything into a nice text format
  74.  
  75.             move.l    a0,a3                    ;a0 points to a list of pointers of the text lines
  76. alllines
  77.             move.l    (a3)+,a2                ;get first (next) line
  78.             cmpa.l    #0,a2                    ;are there anymore lines?
  79.             beq        doneprinting
  80.  
  81.             bsr        getstringlength            ;work out line length for Write
  82.  
  83.             move.l    clihandle,d1
  84.             move.l    a2,d2
  85.             move.l    d0,d3
  86.             CALLDOS    Write                    ;Write it to display
  87.  
  88.             bsr        printreturn                ;Return
  89.             bra        alllines
  90.  
  91. doneprinting    
  92.             bsr        freenodemem                ;free this file nodes memory
  93.             bra        ReadNextFile            ;repeat until no more files
  94.  
  95. errorinread
  96.             bsr        freenodemem            
  97.  
  98. nomorefiles
  99.             move.l    a5,d1                    ;Close everything
  100.             CALLDFB    CloseFileBase
  101. nofilebase
  102.             move.l    _dosbase,a1
  103.             CALLEXEC    CloseLibrary
  104. nodoslibrary
  105.             move.l    _dfbbase,a1
  106.             CALLEXEC    CloseLibrary
  107. nolibrary
  108.             rts
  109.  
  110. getstringlength
  111.             clr.l    d0
  112.             move.l    a2,a0
  113. keepcounting
  114.             addq.l    #1,d0
  115.             tst.b    (a0)+
  116.             bne        keepcounting            
  117.             rts
  118.  
  119. printreturn
  120.             move.l    clihandle,d1
  121.             move.l    #return,d2
  122.             move.l    #3,d3
  123.             CALLDOS    Write
  124.             rts
  125.             
  126. freenodemem
  127.             move.l    a4,a1
  128.             move.l    d4,d0
  129.             CALLEXEC    FreeMem
  130.             rts
  131.             
  132. dfbname        DFBNAME            
  133. dosname        DOSNAME 
  134.  
  135. return        dc.b    lf,cr,0
  136.  
  137.             SECTION    DemoData,BSS
  138.  
  139. _dfbbase    ds.l    1            
  140. _dosbase    ds.l    1
  141. clihandle    ds.l    1
  142.  
  143. freespace    ds.b    1024
  144. clearbyte    ds.b    1
  145.